1. Field of the Invention
The present invention relates to an image encoding technique and, more particularly, to a technique of transforming image data into data in the frequency space and encoding obtained transform coefficients, thereby generating encoded image data.
2. Description of the Related Art
As an image coding method, conventionally, transform coding is used which encodes image data by transforming it into data in the frequency space. JPEG which is recommended as the international standard scheme of still image coding is a typical example of transform coding using DCT (Discrete Cosine Transform) as a technique of transforming data into data in the frequency space. The encoding process of JPEG will briefly be described below.
An encoding target image is divided into blocks each formed from a rectangular region. DCT is applied to each pixel in each block. Coefficients obtained by transform are quantized in accordance with a desired image quality level and code amount. The quantized transform coefficients are entropy-encoded. In JPEG Baseline, Huffman coding is employed as the coefficient entropy-coding method. Since one block includes 8×8 pixels (=64 pixels), one DC component value and 63 AC component values are generated by DCT. The DC component value is encoded as the difference value with respect to the immediately preceding block. Each AC component value is Huffman-coded by combining the number of continuous zeros (zero run) and a non-zero coefficient value.
For efficient encoding using the method of encoding the number of continuous zeros, as in JPEG Baseline, the number of coefficient values that are zero after quantization is preferably as large as possible. To do this, the quantization step value to be used in quantization is made large. However, the larger the quantization step value is, the larger the difference between the original image and an image obtained by decoding is. That is, the quality of the image obtained by decoding degrades.
To place priority on the image quality, the quantization step value is preferably as small as possible. In this case, however, no high encoding efficiency is expected.
To raise the encoding efficiency and simultaneously adopt a small quantization step value, a method has been proposed which separates each coefficient value into an upper-bit portion and a lower-bit portion and applies run-length encoding to only the upper-bit portion.
Japanese Patent Laid-Open No. 2000-13797 discloses an example of an image processing apparatus and method using this conventional technique.
When encoding an image, it is sometimes necessary to control the code amount to a predetermined value or less. For example, a digital camera needs to store a predetermined number of image data in a storage medium having a limited capacity. The code amount control is also required for the purpose of reducing the memory utilization in an image encoding apparatus.
As the means for controlling the code amount, various kinds of methods are proposed. A method of repeating quantization step adjustment and encoding processing until the code amount reaches a target value is supposed to be simplest.
As simpler techniques, methods of controlling the code amount by discarding part of generated encoded data are also known, including a method of, e.g., omitting the lower bits of a coefficient.
The above-described code amount control means for adjusting the quantization step to control the code amount to a target value can finely set the quantization step. It is therefore possible to obtain high image quality within a predetermined code amount. However, this method needs high operation cost and long process time for re-encoding.
Re-encoding requires reconstruction of a coefficient value. To hold an image or a coefficient value, a large memory capacity is necessary. To decode a coefficient from temporarily encoded data and re-encode it, an operation cost for the decoding is needed. Additionally, since the value quantized once is quantized again using another quantization step, fine control is impossible.
In the above-described method of discarding part of a code, omitting lower bits is equivalent to processing of limiting selectable quantization steps to multiples of a power of 2. Since fine control is impossible even in this case, the quality of a reproduced image may have a problem.